package Interface2;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

import admin.Admin;
import admin.Menu;

public class AuthInterceptor implements Interceptor {

	public void intercept(Invocation invocation) {
		Controller controller = invocation.getController();
		try {
			Admin a = controller.getSessionAttr(Admin.Admin_Session);
			if (a == null){
				if ("POST".equals(controller.getRequest().getMethod())) {
					Map<String, String> map = new HashMap<>();
					map.put("message", "no login!");
					map.put("state", "9002");
					System.out.println("先登陆1111111111111");
					controller.renderJson(map);
				}else{
					System.out.println("先登陆333333333333333");
					controller.renderJsp("/jsp/system/login.jsp");
				}
			}else{
				String type = a.getStr("type"); //??????? 都是null
				System.out.println("type:------------》》"+type);
				System.out.println("name:------------》》"+a.getStr("name")); //信昇达
//				if("2".equals(type)){
//					controller.setAttr("mList", Menu.dao.menuListByRoleid(a.getInt("roleId")));
//				}
				controller.setAttr("adminName", a.getStr("name"));
				invocation.invoke();
			}
		} catch (NullPointerException e) {
		}
	}

}